package com.neusoft.util;

import java.util.Random;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import com.aliyun.teaopenapi.models.Config;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import static com.aliyun.teautil.Common.toJSONString;
@Component
public class VerificationCode {
	public VerificationCode() {};
	public static String generateVerificationCode() {
		// 设置验证码长度为6
		int length = 6;
		// 验证码字符集
		String digits = "0123456789";
		Random random = new Random();
		StringBuilder sb = new StringBuilder();

		// 生成六位数验证码
		for (int i = 0; i < length; i++) {
			int index = random.nextInt(digits.length());
			sb.append(digits.charAt(index));
		}
		return sb.toString();
	}
	public static com.aliyun.dysmsapi20170525.Client createClient() throws Exception {
        // 工程代码泄露可能会导致 AccessKey 泄露，并威胁账号下所有资源的安全性。以下代码示例仅供参考。
        // 建议使用更安全的 STS 方式，更多鉴权访问方式请参见：https://help.aliyun.com/document_detail/378657.html。
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId("LTAI5tGS4Gqre3JhG7tYCdpS")
                .setAccessKeySecret("KBG20ZTvuP5d5CHA1YPCo4k79abvwd");
        // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }
}
